package cn.itcast.bos.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.bos.domain.Decidedzone;
import cn.itcast.bos.domain.pagebean.PageBean;
import cn.itcast.bos.web.action.base.BaseAction;
import cn.itcast.crm.domain.Customer;
import cn.itcast.crm.service.CustomerService;

@Controller
@Scope("prototype")
public class DecidedzoneAction extends BaseAction<Decidedzone>{
	
	//使用数组接收多个 分区id  在subarea类中提供一个 get方法
	private String[] subareaid;
	public void setSubareaid(String[] subareaid) {
		this.subareaid = subareaid;
	}

	//saveDecidezone
	public String saveDecidezone(){
		decidedzoneService.save(model,subareaid);
		return "decidedzonelist";
	}
	
	//pageQuery定区分页查询
	public String pageQuery(){
		decidedzoneService.pageQueryList(pageBean);
		this.writeObjectFastjson(pageBean, new String[]{"subareas","decidedzones"});
		return NONE;
	}
	
	//NoassociationSelect 查询未关联定区的远程crm
	@Resource
	private CustomerService customerService;
	public String NoassociationSelect(){
		List<Customer> list = customerService.findnoassociationCustomers();
		this.writeObjectFastjson(list, new String[]{"decidedzone_id"});
		return NONE;
	}
	
	//"associationSelect
	private String diciedzoneid;
	public void setDiciedzoneid(String diciedzoneid) {
		this.diciedzoneid = diciedzoneid;
	}

	public String associationSelect(){
		List<Customer> list=customerService.findhasassociationCustomers(diciedzoneid);
		this.writeObjectFastjson(list, new String[]{"decidedzone_id"});
		return NONE;
	}
	
	//assigncustomerstodecidedzone 
	private Integer[] customerIds;
	public void setCustomerIds(Integer[] customerIds) {
		this.customerIds = customerIds;
	}

	public String assigncustomerstodecidedzone(){
		customerService.assignCustomersToDecidedZone(customerIds,model.getId());
		return "decidedzonelist";
	}
	
}
